<script type="text/javascript">
//ES6 引入了一种新的原始数据类型 Symbol ，表示独一无二的值，最大的用法是用来定义对象的唯一属性名。
let sy = Symbol("KK");
console.log(sy);   // Symbol(KK)
typeof(sy);        // "symbol"
document.write('<br>');
document.write(typeof(sy));

// 相同参数 Symbol() 返回的值不相等
let sy1 = Symbol("kk"); 
document.write('<br>');
if(sy === sy1){
	document.write("same");
}else{
	document.write("not same");
}


const COLOR_RED = "red";
const COLOR_YELLOW = "yellow";
const COLOR_BLUE = "blue";
const MY_BLUE = "blue";
/*const COLOR_RED = Symbol("red");
const COLOR_YELLOW = Symbol("yellow");
const COLOR_BLUE = Symbol("blue");*/
 //document.write(COLOR_RED);
function ColorException(message) {
   this.message = message;
   this.name = "ColorException";
}
 
function getConstantName(color) {
    switch (color) {
        case COLOR_RED :
            return "COLOR_RED";
        case COLOR_YELLOW :
            return "COLOR_YELLOW ";
        case COLOR_BLUE:
            return "COLOR_BLUE";
        case MY_BLUE:
            return "MY_BLUE";         
        default:
            throw new ColorException("Can't find this color");
    }
}

document.write('<br>');
try {
   
   //var color = "green"; // green 引发异常
   var color = "red";
   var colorName = getConstantName(color);
   document.write(COLOR_RED);
   document.write(colorName);
} catch (e) {
   var colorName = "unknown";
   console.log(e.message, e.name); // 传递异常对象到错误处理
   
   document.write(e.message, e.name);
}
</script>